package com.cnap.multiclouldmgmt.model.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * 枚举类型
 * @author dyq
 */
public enum CreateVmStepEnum {

    Init(0,"刚初始化","init"),

    CloudCreate(1,"开始创建云主机","cloudCreate"),

    Cloud(2,"云主机创建完成","cloud"),

    PortCreate(3,"创建安全组","portCreate"),

    Port(4,"创建安全组完成","port"),

    K8sCreate(5,"建立集群","k8sCreate"),

    K8s(6,"集群建立成功","k8s"),

    End(99,"流程结束","end");

    private int index;

    private String chineseDescribe;

    private String describe;

    CreateVmStepEnum(int index,String chineseDescribe, String describe) {

        this.index = index;
        this.chineseDescribe = chineseDescribe;
        this.describe = describe;
    }

    public static String getRetryStepDescribe(String type) {

        if (StringUtils.equals(type,Init.describe)){
            return Init.describe;
        }

        if (StringUtils.equals(type,CloudCreate.describe)){
            return Init.describe;
        }

        if (StringUtils.equals(type,Cloud.describe)){
            return Init.describe;
        }

        if (StringUtils.equals(type,PortCreate.describe)){
            return Cloud.describe;
        }

        if (StringUtils.equals(type,Port.describe)){
            return Cloud.describe;
        }

        if (StringUtils.equals(type,K8sCreate.describe)){
            return Port.describe;
        }

        if (StringUtils.equals(type,K8s.describe)){
            return Port.describe;
        }

        return type;
    }

    public static String getDescribeByIndex(int typeIndex) {

        for(CreateVmStepEnum enumObj : CreateVmStepEnum.values()){

            if (enumObj.getIndex() == typeIndex){

                return enumObj.getDescribe();
            }
        }

        return Init.getDescribe();
    }


    /**
     * get
     *
     * @return ChineseDescribe
     */
    public String getChineseDescribe() {
        return chineseDescribe;
    }

    /**
     * set
     *
     * @param chineseDescribe chineseDescribe
     */
    public void setChineseDescribe(String chineseDescribe) {
        this.chineseDescribe = chineseDescribe;
    }

    /**
     * get
     *
     * @return Describe
     */
    public String getDescribe() {
        return describe;
    }

    /**
     * set
     *
     * @param describe describe
     */
    public void setDescribe(String describe) {
        this.describe = describe;
    }

    /**
     * get
     *
     * @return Index
     */
    public int getIndex() {
        return index;
    }

    /**
     * set
     *
     * @param index index
     */
    public void setIndex(int index) {
        this.index = index;
    }

    public static String getChineseDescribeByDescribe(String describe){
        
        for(CreateVmStepEnum enumObj : CreateVmStepEnum.values()){

            if (enumObj.getDescribe().equals(describe)){

                return enumObj.getChineseDescribe();
            }
        }

        return describe;
    }

    public static String getDescribeByChineseDescribe(String chineseDescribe){

        for(CreateVmStepEnum enumObj : CreateVmStepEnum.values()){

            if (enumObj.getChineseDescribe().equals(chineseDescribe)){

                return enumObj.getDescribe();
            }
        }

        return chineseDescribe;
    }

    public static int getIndexByDescribe(String describe){

        for(CreateVmStepEnum enumObj : CreateVmStepEnum.values()){

            if (enumObj.getDescribe().equals(describe)){

                return enumObj.getIndex();
            }
        }

        return 0;
    }

    /**
     * 判断当前步骤是否要通知部署方
     * @param describe 当前步骤
     */
    public static boolean checkSendMsgStep(String describe){
        int index = getIndexByDescribe(describe);

        return index % 2 == 0;
    }

    /**
     * 判断当前步骤是否要做执行动作
     * @param describe 当前步骤
     */
    public static boolean checkHandleStep(String describe){
        int index = getIndexByDescribe(describe);
        if (index == 0){
            return true;
        }

        return index % 2 != 0;
    }
}
